package com.itouchtv.yang.core.eventListener;

import com.itouchtv.yang.core.Enum.ResultEnum;
import com.itouchtv.yang.core.driver.CommDriver;
import com.itouchtv.yang.core.tools.Log;
import com.itouchtv.yang.core.tools.Screen;
import io.appium.java_client.events.api.general.AppiumWebDriverEventListener;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.events.AbstractWebDriverEventListener;

/**
 * selenium操作事件监听
 */
public class MySeleniumEventListener extends AbstractWebDriverEventListener implements AppiumWebDriverEventListener{
    @Override
    public void beforeAlertAccept(WebDriver webDriver) {
    }

    @Override
    public void afterAlertAccept(WebDriver webDriver) {
    }

    @Override
    public void afterAlertDismiss(WebDriver webDriver) {
    }

    @Override
    public void beforeAlertDismiss(WebDriver webDriver) {
    }

    @Override
    public void beforeNavigateTo(java.lang.String url, WebDriver driver) {
        Log.logger.info("准备跳转到:" + url);
    }

    @Override
    public void afterNavigateTo(java.lang.String url, WebDriver driver) {
        Log.logger.info("成功跳转到:" + url);
    }

    @Override
    public void beforeNavigateBack(WebDriver webDriver) {
        Log.logger.info("返回上一页");
    }

    @Override
    public void afterNavigateBack(WebDriver webDriver) {
        Log.logger.info("返回成功");
    }

    @Override
    public void beforeNavigateForward(WebDriver webDriver) {
        Log.logger.info("操作向前一页");
    }

    @Override
    public void afterNavigateForward(WebDriver webDriver) {
        Log.logger.info("操作向前一页成功");
    }

    @Override
    public void beforeNavigateRefresh(WebDriver webDriver) {
        Log.logger.info("刷新页面前");
    }

    @Override
    public void afterNavigateRefresh(WebDriver webDriver) {
        Log.logger.info("刷新页面后");
    }

    @Override
    public void beforeFindBy(By by, WebElement webElement, WebDriver webDriver) {
    }

    @Override
    public void afterFindBy(By by, WebElement webElement, WebDriver webDriver) {
    }

    @Override
    public void beforeClickOn(WebElement webElement, WebDriver webDriver) {
    }

    @Override
    public void afterClickOn(WebElement webElement, WebDriver webDriver) {
        Screen.ScreenShot(CommDriver.driver.get(), ResultEnum.CLICK);
    }

    @Override
    public void beforeChangeValueOf(WebElement element, WebDriver driver) {

    }

    @Override
    public void beforeChangeValueOf(WebElement webElement, WebDriver webDriver, CharSequence[] charSequences) {
    }

    @Override
    public void afterChangeValueOf(WebElement element, WebDriver driver) {

    }

    @Override
    public void afterChangeValueOf(WebElement webElement, WebDriver webDriver, CharSequence[] charSequences) {
    }

    @Override
    public void beforeScript(java.lang.String script, WebDriver driver) {
    }

    @Override
    public void afterScript(java.lang.String script, WebDriver driver) {
    }

    @Override
    public void beforeSwitchToWindow(java.lang.String windowName, WebDriver driver) {
        Log.logger.info("before SwitchTo Window");
    }

    @Override
    public void afterSwitchToWindow(java.lang.String windowName, WebDriver driver) {
        Log.logger.info("after SwitchTo Window");
    }

    @Override
    public void onException(Throwable throwable, WebDriver webDriver) {
        Log.logger.error(throwable.getMessage());
    }

    @Override
    public <X> void beforeGetScreenshotAs(OutputType<X> outputType) {
    }

    @Override
    public <X> void afterGetScreenshotAs(OutputType<X> outputType, X x) {
    }
}
